grammar compilost;

start	
	:	expression $
	;


expression
	: 	(relational_expression) (op_logico expression)*
	;



relational_expression
	: 	(additive_expression) (op_relacional relational_expression)*
	;

additive_expression
	:	(multiplicative_expression) (op_soma additive_expression)* 
	;
	
	
multiplicative_expression
	: 	(cast_expression) (op_mult multiplicative_expression)*
	;

cast_expression
	: unary_expression //retorna valor
	| '(' nome_tipo ')' cast_expression
	;

unary_expression
	: postfix_expression //retorna valor
	| op_inc_dec unary_expression
	| op_unario  cast_expression
	;

postfix_expression
	: (primary_expression) (( '[' expression ']' |'(' ')'| '(' argument_expression_list ')'| op_inc_dec ))*
	;


primary_expression
	: 'IDENTIFIER'
	| 'CONSTANT'
	| '(' expression ')'
	;


argument_expression_list
	: assignment_expression ( ',' assignment_expression)*
	;

assignment_expression
	: expression
	| unary_expression '=' assignment_expression
	;





op_logico	:	'&&'
	|	'||'
	;
	
	
	
op_mult	:	'*'
	|	'/'
	;
	
	
op_unario
	: 	op_soma
	|	'!'
	; 

op_relacional
	:	'>'
	|	'<'
	|	'<='
	| 	'>='
	| 	'=='
	|	'!=';
	
	
op_soma
	:	'-'
	|	'+'
	;
	
	
op_inc_dec
	:	'--'
	|	'++'
	;
	

	
nome_tipo
	:	'inteiro'
	|	'caractere'
	|	'real'
	|	'string'
	;
	